﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using usedcartrade.ViewModels;
using usedcartrade.Models;
using usedcartrade.Filter;

namespace usedcartrade.Controllers
{
    public class UserManageController : Controller
    {
        // GET: UserManage
        [AdminFilter]
        public ActionResult Index()
        {
            UserListViewModel userListViewModel = new UserListViewModel();
            UserBusinessLayer usrBal = new UserBusinessLayer();
            List<User> users = usrBal.GetUsers();
            List<UserViewModel> usrViewModels = new List<UserViewModel>();

            foreach(User usr in users)
            {
                UserViewModel usrViewModel = new UserViewModel();
                usrViewModel.UserName = usr.userDetails.UserName;
                usrViewModel.Phone = usr.userDetails.Phone;
                usrViewModel.Email = usr.userDetails.Email;
                usrViewModel.City = usr.userDetails.City;
                usrViewModels.Add(usrViewModel);
            }
            userListViewModel.Users = usrViewModels;
            return View("Index",userListViewModel);
        }
    }
}